/*
 *  WsvJdbc - a JDBC driver for WSV (values separated by whatever) data files
 *  Copyright (C) 2004  Daniele Pes
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 2.1 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package axs.jdbc.dataSourceConfiguration;

import axs.jdbc.dataSpecification.SqlTypes;


/**
 * This class is used to specify the properties of a column in a plain text data table (for the WsvJdbc driver).
 * 
 * @author 		Daniele Pes
 * @version    $Id: ColumnSpecification.java,v 1.2 2007/04/16 17:24:36 montag451 Exp $
 */
public class ColumnSpecification {
	private String  columnName;
	private Integer columnType;
	private int     strColWidth;
	private int		 beginPos;	
	private int		 endingPos;
   private boolean trim;

   
   public ColumnSpecification() {
		columnName = "";
		columnType = null;
   }

	   
   public String getColumnName() {
      return columnName;
   }


   public Class getColumnType() {
      return SqlTypes.getAvalidSqlType(columnType);
   }


	public int getColumnSQLtype() {
		return columnType.intValue();
	}


	public String getColumnSQLtypeName() {
		return SqlTypes.getAvalidSqlTypeName(columnType);
	}
	
	public boolean isTrim() {
      return trim;
   }
    
   public void setColumnName(String name) {
      columnName = name;
   }


   public void setColumnType(Integer type) {
      columnType = type;
   }


   public void setColumnType(int type){
   	columnType = new Integer(type);
   }


	public void setColumnType(Class type) {
		columnType = (Integer)SqlTypes.getJavaSqlTypesToSqlInteger(type);
	}
	
	
	public int getStrColWidth() {
		return strColWidth;
	}

	
	public void setStrColWidth(int width) {
		strColWidth = width;
	}


	public void setStrColWidth(Integer width) {
		strColWidth = width.intValue();
	}
	
	
	public int getEndingPos() {
		return endingPos;
	}

	
	public int getBeginPos() {
		return beginPos;
	}

	
	public void setEndingPos(int i) {
		endingPos = i;
	}

	
	public void setEndPos(int i) {
		beginPos = i;
	}   
     
   public void setTrim(boolean trim) {
      this.trim = trim;
   }    

	public String toString(){
		String typeName;
		//
		typeName = SqlTypes.getAvalidSqlTypeName(columnType);
		return "\n" +
			    "[name                 = " + getColumnName() + "]\n" + 
				 "[type                 = " + typeName + "]\n" + 
				 "[starting position    = " + getBeginPos() + "]\n" + 
				 "[ending position      = " + getEndingPos() + "]\n" + 
				 (typeName.equals("VARCHAR")?"[width                = " + getStrColWidth() + "]\n":"\n") +
             (typeName.equals("VARCHAR")?"[trim if fixed length = " + isTrim() + "]\n":"\n");
	}    
}
